package com.njcky.utils.citylife;

/**
 * @BelongsProject: BladeX-Biz
 * @BelongsPackage: com.yutu.infrastructure.utils
 * @Author: ZYin
 * @CreateTime: 2023-02-10  15:02
 * @Description: TODO
 * @Version: 1.0
 */

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

public class BigDecimalSerializer extends JsonSerializer<BigDecimal> {
	public BigDecimalSerializer() {
	}

	public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		if (value != null) {
			BigDecimal number = value.setScale(3, BigDecimal.ROUND_HALF_UP);
			gen.writeNumber(number);
		} else {
			gen.writeNumber(value);
		}

	}
}

